package edu.zhuravlev.trainingbot.service;


import edu.zhuravlev.trainingbot.exception.SystemException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.TelegramClient;

@Service
@RequiredArgsConstructor
public class SenderService {

    private final TelegramClient telegramClient;

    public void sendSimpleText(String chatId, String text) {
        sendMessage(new SendMessage(chatId, text));
    }

    public void sendMessage(SendMessage sendMessage) {
        try {
            telegramClient.execute(sendMessage);
        } catch (TelegramApiException e) {
            throw new SystemException(e.getLocalizedMessage());
        }
    }

}
